﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MiniSched.Web.Controllers {

    [Authorize]
    public abstract class BaseController : Controller {

        internal BaseController() { }

        internal ActionResult RedirectToLocal(string url) {
            if (Url.IsLocalUrl(url)) {
                return Redirect(url);
            }
            else {
                return RedirectToAction("Index", "Home");
            }
        }
    }

    public abstract class BaseController<TApi> : BaseController where TApi : IDisposable, new() {

        internal TApi Api {
            get {
                if (null == _Api) _Api = new TApi();
                return _Api;
            }
        }
        private TApi _Api;

        internal BaseController() { }

        protected override void Dispose(bool disposing) {
            if (disposing) {
                if (_Api != null) {
                    _Api.Dispose();
                }
            }
            base.Dispose(disposing);
        }
    }
}
